// JavaScript Document
function setTab(name,cursel,n){
	for(i=1;i<=n;i++){
		var menu=document.getElementById(name+i);
		var con=document.getElementById("con_"+name+"_"+i);
		menu.className=i==cursel?"hover":"";
		con.style.display=i==cursel?"block":"none";
		var img_lazy_load = img_lazy(con);
		img_lazy_load();
		if (con.style.display != 'none') {
			con.addEventListener('scroll', img_lazy_load);
		} else {
			con.removeEventListener('scroll', img_lazy_load);
		}
	}
}

function img_lazy(ele) {
	function objpos(obj){
		var pre = obj;
		var l = 0;
		var t = 0;
		while (obj) {
			if(obj == pre){
				t += obj.offsetTop;
				l += obj.offsetLeft;
				obj = obj.offsetParent;
			} else {
				t += obj.offsetTop + obj.clientTop;
				l += obj.offsetLeft + obj.clientLeft;
				obj = obj.offsetParent;
			}
		}
		return {top:t,left:l};
	}

	var imgs = Array.prototype.slice.call(ele.getElementsByTagName('img'), 0);
	var parentClientHeight = ele.clientHeight;
	var parentOffsetTop = objpos(ele).top;
	return function () {
		for (var i = 0; i < imgs.length; i++) {
			if (objpos(imgs[i]).top - parentOffsetTop < parentClientHeight + $(ele).scrollTop()) {
				var dataSrc = imgs[i].getAttribute("data-src");
				dataSrc && imgs[i].setAttribute("src", dataSrc);
				imgs[i].style.display = "inline-block";
				imgs.splice(i,1);
				i--;
			}
		}
	}
	
}
